home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / Q-R / QB Graphics.sea / patterns.bas < prev    next >
BASIC Source File  |  1991-06-04  |  5KB  |  145 lines

  1. '------------------------------------------------------------------------------
  2. ' TITLE:    Patterns
  3. ' DATE:     February 2, 1991
  4. ' AUTHOR: R. Gonzalez
  5. '
  6. ' DESCRIPTION:    Draw patterns on screen.  REQUIRES COLOR OR GRAY-SCALE,
  7. '    unless you modify modify the code to eliminate the color-selection.
  8. '
  9. ' COMPILING:    Remove STATIC declarations, uncomment indicated lines
  10. '     Check: Include MBPCs & MBLCs, Include runtime code, Make all arrays static,
  11. '     Use default window & menu, (if available: Generate 68020 & 68881 code).
  12. '
  13. ' (MODIFICATION HISTORY)
  14. ' DATE:
  15. ' AUTHOR:
  16. ' DESCRIPTION:
  17. '------------------------------------------------------------------------------
  18.  
  19. ' these variables may be shared among several subprograms:
  20. DIM SHARED TRUE%,FALSE%,PI
  21.  
  22. ' user defined functions must be declared at top of source file:
  23. DEF FNrnd.color% = INT(RND*8)    'returns a random color
  24.  
  25. '------------------------------------------------------------------------------
  26. ' main procedure
  27. '------------------------------------------------------------------------------
  28. 'MAIN
  29.  
  30.     DIM color.value%(7)
  31.     DIM fcol%,bcol%,done%    'I like to declare all variables, array or otherwise
  32.  
  33.     TRUE% = -1
  34.     FALSE% = 0
  35.     PI = 3.14159
  36.     initialize color.value%()
  37.     done% = FALSE%
  38.  
  39.     RANDOMIZE TIMER    'seed random number generator with time
  40.  
  41.     ' Here's the main event loop:
  42.     WHILE NOT done%
  43.         
  44.         set.colors fcol%,bcol%,color.value%()
  45.         CLS        'clear screen with background color
  46.         PRINT "Fore:";fcol%;"Back:";bcol%
  47.         draw.figure PI/60!
  48.         sleep 2!
  49.         check.if.done done%
  50.  
  51.     WEND
  52.  
  53. END
  54.  
  55. '------------------------------------------------------------------------------
  56. ' initialize color/gray-scale values
  57. '------------------------------------------------------------------------------
  58. SUB initialize (color.value%()) STATIC
  59.  
  60.     color.value%(0) = 30      'white                            white
  61.     color.value%(1) = 69      'very close to white       yellow
  62.     color.value%(2) = 273    'light gray                      cyan
  63.     color.value%(3) = 137    'gray                              magenta
  64.     color.value%(4) = 341    'dark gray                      green
  65.     color.value%(5) = 409    'black or very close       blue
  66.     color.value%(6) = 205    'black or very close       red
  67.     color.value%(7) = 33      'black                            black
  68.  
  69. END SUB
  70.  
  71. '------------------------------------------------------------------------------
  72. ' set foreground and background colors
  73. '------------------------------------------------------------------------------
  74. SUB set.colors (col1%,col2%,color.value%()) STATIC
  75.  
  76.     col1% = FNrnd.color%
  77.     col2% = FNrnd.color%
  78.     WHILE col1% = col2%        'avoid black-on-black, etc.
  79.         col1% = FNrnd.color%
  80.     WEND
  81.     forecolor color.value%(col1%)        'Toolbox call to set drawing color
  82.     backcolor color.value%(col2%)       'Toolbox call to set background color
  83.  
  84. END SUB
  85.  
  86. '------------------------------------------------------------------------------
  87. ' draw a random figure made up of lines.
  88. ' Since QuickBASIC is rather slow in making subprogram calls, it's best to avoid
  89. ' calling a subprogram in a critical loop, such as within the FOR loop below.
  90. '------------------------------------------------------------------------------
  91. SUB draw.figure (increment) STATIC
  92.  
  93.     ' for compiler only (since you can't have STATIC subprograms):
  94. '    dim window.width%,window.height%
  95. '    dim x,x1,x2,y1,y2,a,b,c,d,e,f,g,h
  96.  
  97.     window.width% = WINDOW(2)/2!    'actively find window width
  98.     window.height% = WINDOW(3)/2!    'actively find window height
  99.     a = RND * 2!
  100.     b = RND * 2!
  101.     c = RND * 2!
  102.     d = RND * 2!
  103.     e = RND * PI * 2!
  104.     f = RND * PI * 2!
  105.     g = RND * PI * 2!
  106.     h = RND * PI * 2!
  107.  
  108.     FOR x = 0! TO 2!*PI STEP increment
  109.         x1 = SIN(x * a + e) * window.width% * .95 + window.width%
  110.         y1 = SIN(x * b + f) * window.height% * .95 + window.height%
  111.         x2 = SIN(x * c + g) * window.width% * .95 + window.width%
  112.         y2 = SIN(x * d + h) * window.height% * .95 + window.height%
  113.         LINE (x1, y1)-(x2, y2)        'draw line using foreground color
  114.     NEXT
  115.  
  116. END SUB
  117.  
  118. '------------------------------------------------------------------------------
  119. ' change value of argument if mouse or any key is pressed
  120. '------------------------------------------------------------------------------
  121. SUB check.if.done (test%) STATIC
  122.  
  123.     IF INKEY$ <> "" OR MOUSE(0) = 1 THEN
  124.         test% = TRUE%   
  125.     END IF
  126.             
  127. END SUB
  128.  
  129. '------------------------------------------------------------------------------
  130. ' wait specified number of seconds
  131. '------------------------------------------------------------------------------
  132. SUB sleep (sleep.time) STATIC
  133.  
  134.     ' for compiler only:
  135. '    dim start.time
  136.  
  137.     start.time = TIMER
  138.     WHILE TIMER < start.time + sleep.time
  139.     WEND
  140.         
  141. END SUB
  142.     
  143.     
  144.  
  145.